﻿using System;
using System.Collections.Generic;
using System.Linq;
using Lypshare.Net;

namespace Lypshare.ChatApp
{
	/// <summary>
	/// Message packet.
	/// </summary>
	/// <exception cref='ArgumentNullException'>
	/// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
	/// </exception>
    public class MessagePacket : Packet
    {
        // --------------------------------------------------------
        // Class Properties
        // --------------------------------------------------------


        /// <summary>
        /// Gets or sets the message.
        /// </summary>
        /// <value>
        /// The message.
        /// </value>
        public String Message
        {
            get;
            set;

        } // Property: Message


        // --------------------------------------------------------
        // Class Functions
        // --------------------------------------------------------


        /// <summary>
        /// Initializes a new instance of the <see cref="Lypshare.ChatApp.MessagePacket"/> class.
        /// </summary>
        public MessagePacket()
        {
        } // Constructor


        /// <summary>
        /// Initializes a new instance of the <see cref="Lypshare.ChatApp.MessagePacket"/> class.
        /// </summary>
        /// <param name='message'>
        /// Message.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        public MessagePacket(String message)
        {
            if (message == null)
                throw new ArgumentNullException("message");

            Message = message;

        } // Constructor


        /// <summary>
        /// Parse the specified buffer.
        /// </summary>
        /// <param name='buffer'>
        /// Buffer.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        protected override void Parse(PacketBuffer buffer)
        {
			if(buffer == null)
				throw new ArgumentNullException("buffer");
			
            Message = buffer.ReadString();
            base.Parse(buffer);

        } // Parse


        /// <summary>
        /// Encode the specified buffer.
        /// </summary>
        /// <param name='buffer'>
        /// Buffer.
        /// </param>
        /// <exception cref='ArgumentNullException'>
        /// Is thrown when an argument passed to a method is invalid because it is <see langword="null" /> .
        /// </exception>
        protected override void Encode(PacketBuffer buffer)
        {
			if(buffer == null)
				throw new ArgumentNullException("buffer");
			
            buffer.Write(Message);
            base.Encode(buffer);

        } // Encode

    } // class MessagePacket
} // namespace Lypshare.ChatApp